import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';

class GridGood extends StatefulWidget {
  GridGood({Key key, this.list}) : super(key:key);
  final List list;
  @override
  _GridGoodState createState() => _GridGoodState();
}

class _GridGoodState extends State<GridGood> {
  List list;
  @override
  void initState() {
    list = widget.list;
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context,width:750,height:1334);
    return SliverPadding(
      padding: EdgeInsets.all(ScreenUtil().setWidth(20)),
      // SliverStaggeredGrid
      //StaggeredGridView
      sliver: SliverStaggeredGrid.countBuilder(
        crossAxisCount: 4,
        itemCount: 20,
        itemBuilder: (BuildContext context, int index) => new Container(
          color: Colors.yellow[300],
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Expanded(
                child: Image.network(
                "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2259614868,961155351&fm=26&gp=0.jpg",
                fit: BoxFit.cover,
              ),
              ),
              Container(
                padding: EdgeInsets.all(ScreenUtil().setWidth(20)),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text("商品"+index.toString()),
                    Text("商品描述"+index.toString(),style: TextStyle(fontSize: ScreenUtil().setWidth(26),color:Colors.grey[600])),
                    Text("￥99.99",style: TextStyle(color: Colors.red),)
                  ],
                ),
              )
            ],
          )
        ),
        staggeredTileBuilder: (int index) {
          return new StaggeredTile.count(2, index%4==0 ? 3 :2.5);
        },
        mainAxisSpacing: ScreenUtil().setWidth(20),
        crossAxisSpacing: ScreenUtil().setWidth(20),
      ),
    );
  }
}